using System;
using System.Text ;
using System.Data ;
using System.Collections ;

using WP.MF.BusinessRule; 
using WP.MF.DataEntity; 
using WP.MF.DataAccess; 
using WP.Commons;
using WP.DB;

namespace WP.MF.BusinessLogical
{
	/// <summary>
	/// Summary description for MRemitToBLL.
	/// </summary>
    public class MRemitToBLL : IBusinessLogical
	{
		MRemitToDAL mRemitToDAL=new MRemitToDAL();

		public MRemitToBLL()
		{
		}

        #region For implement interface

        #region Select Record by RECID OverLoad +1
        public MRemitToDEL SelectDataByRecID(DBAccess dBAccess, string strRecId)
        {
            MRemitToDEL mRemitToDEL = new MRemitToDEL();

            DataFunctions.SelectByRecID(dBAccess, mRemitToDEL, mRemitToDAL.Fields, strRecId);

            return mRemitToDEL;
        }
        public IDataEntity SelectDataByRecID(string strRecId)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            MRemitToDEL mRemitToDEL = null;

            try
            {
                mRemitToDEL = SelectDataByRecID(dBAccess, strRecId);
                return mRemitToDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }
        #endregion

        #region public bool Insert()
        public bool Insert(IDataEntity iMRemitToDEL)
        {
            bool bReturn = true;
            MRemitToDEL mRemitToDEL = iMRemitToDEL as MRemitToDEL;
            DBAccess dBAccess = null;

            dBAccess = new DBAccess(false, true);
            try
            {
                bReturn = Insert(dBAccess, mRemitToDEL);

                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                bReturn = false;
            }
            return bReturn;
        }
        public bool Insert(DBAccess dBAccess, MRemitToDEL mRemitToDEL)
        {
            bool bFlag = true;
            MRemitToBRL mRemitToBRL = new MRemitToBRL();

            if (mRemitToBRL.InsertValid(dBAccess, mRemitToDEL))
            {
                DataFunctions.InsertTable(dBAccess, mRemitToDAL.Fields, mRemitToDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        #endregion

        #region public bool Delete()
        public bool Delete(string strRecId, byte[] btOldRecStamp)
        {
            DBAccess dBAccess = new DBAccess(false, true);
            bool bFlag = false;

            try
            {
                if (new MRemitToBRL().DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    DataFunctions.DeleteByRecID(dBAccess, "mRemitTo", strRecId);

                    dBAccess.CommitTranAndCloseCon();

                    bFlag = true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
            }

            return bFlag;
        }
        #endregion

        #region public bool Update()
        public bool Update(IDataEntity iMRemitToDEL)
        {
            bool bReturn = true;
            MRemitToDEL mRemitToDEL = iMRemitToDEL as MRemitToDEL;
            DBAccess dBAccess = new DBAccess(false, true);

            try
            {
                bReturn = Update(dBAccess, mRemitToDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }

            return bReturn;
        }
        public bool Update(DBAccess dBAccess, MRemitToDEL mRemitToDEL)
        {
            bool bFlag = true;
            MRemitToBRL mRemitToBRL = new MRemitToBRL();

            if (mRemitToBRL.UpdateValid(dBAccess, mRemitToDEL))
            {
                DataFunctions.UpdateTable(dBAccess, mRemitToDAL.Fields, MRemitToDEL.TABLENAME_MREMITTO, mRemitToDEL.Tables[0].Rows[0]);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        #endregion

        #endregion

		#region Select MRemitTo for list
		public DataView SelectMRemitToForList()
		{
			DBAccess dBAccess=new DBAccess();
			return mRemitToDAL.SelectMRemitToForList(dBAccess);
		}
		#endregion
	}
}



